var db = require('mongoose');
db.Promise = global.Promise;
db.connect('mongodb://localhost/Palpha');
var UserSchema = new db.Schema({
    name: String,
    nick_name: String,
    email:String,
    pwd: String,
    t_user_info:{
        type:Object,
        default:{
            t_name:'',
            phone:'',
        }
    },
    c_statu: Object,
    sys_msg:Array,
    head_color: {
        type: Number,
        default: 0
    },
    like_list: {
        type: Array,
        default: []
    },
    topic_admin_list:{
        type: Array,
        default: []
    },
    topic_like_list:{
        type: Array,
        default: []
    },
    head_img: {
        type: String,
        default: '/header/default/header.jpg'
    },
    statu: {
        type: String,
        default: 'normal'
    }
});
var User = db.model('user', UserSchema)
var TopicSchema = new db.Schema({
    name: String,
    admin_id: {
        type:String,
        default:''
    },
    admin_name:{
        type:String,
        default:''
    },
    creater_id:{
        type: db.SchemaTypes.ObjectId,
        ref: 'user'
    },
    note_count:Number,
    p0000_count:Number,
    like_count:Number,
    creater_name:String,
    tops: Array,
    bans: Array,
    type: {
        type: String,
        default: "free"
    },
    statu: {
        type: String,
        default: 'normal'
    },
    tags: Array
})
var Topic = db.model('topic', TopicSchema)
var LogSchema=new db.Schema({
    user_id: {
        type: db.SchemaTypes.ObjectId,
        ref: 'user'
    },
    user_name:String,
    action:String,
    target:Object,
    date:{
        type:Date,
        default:Date.now()
    },
})
var BAdminchema=new db.Schema({
    user_id: {
        type: db.SchemaTypes.ObjectId,
        ref: 'user'
    },
    topic_id:String,
    topic_name:String,
    user_name:String,
    phone:String,
    t_name:String,
    statu:{
        type:String,
        default:'no-read'
    },
    date:{
        type:Date,
        default:Date.now()
    },
})
var Log=db.model('log',LogSchema)
var BAdmin=db.model('badmin',BAdminchema)

var NoteSchema = new db.Schema({
    name: String,
    author_id: {
        type: db.SchemaTypes.ObjectId,
        ref: 'user'
    },
    author_name:String,
    topic_id: {
        type: db.SchemaTypes.ObjectId,
        ref: 'topic'
    },
    topic_name:String,    
    tar_id:{
        type: String,
        default:'0000'
    },
    tar_author_id:String,
    tar_content_id:String,
    tar_author_name:String,
    tar_content:String,
    statu: {
        type: String,
        default: 'normal'
    },
    content: String,
    ans_count:Number,
    click_count:Number,
    like_count:Number,
    statu: {
        type: String,
        default: 'normal'
    },
    is_del:{
        type:Boolean,
        default:false,
    },
    date:{
        type:Date,
        default:Date.now()
    },
})
var Note = db.model('note', NoteSchema);

module.exports = {
    User: User,
    Topic: Topic,
    Note: Note,
    Log:Log,
    BAdmin:BAdmin,
}